Skip to content

perf: limit Find highlights to visible editors - #12245

Merged
mscolnick merged 3 commits into
mainfrom
kg/visible-find-highlights
Dec 3, 2026
Merged

mscolnick merged 3 commits into
mainfrom
kg/visible-find-highlights

Conversation

@kirangadhave

@kirangadhave kirangadhave commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

📝 Summary

Share one Find highlight query and dispatch it to visible CodeMirror editors. A new editor starts with the current query. An editor that returns to the viewport receives the latest query or clear. Counts and replacements still read cell documents, including cells whose editors have yet to mount. Cells in collapsed sections without handles remain outside the search scope.

Find Next still builds the destination editor on demand and keeps keyboard focus in Find. Skip selection resets that leave the caret unchanged. Refresh the match count after undoing Replace All.

Addresses the Find highlight work in MO-8797.

Production benchmark

Four alternating pairs on the 500-cell smoke fixture in headless Chromium at 1280 × 720 and 1× CPU. Both builds use f54c35700e as the base. The fresh case had 2 mounted editors. Traversal mounted 251. Both cases had 2 visible editors at the top of the notebook. Both builds reported 4,051 matches for json.

Notebook Action Editor dispatches Next paint (ms) Forced layouts Forced layout time (ms)
fresh Open with retained query 2 → 2 39.32 → 31.47 2 → 1 3.24 → 2.01
fresh Type one character 2 → 2 25.8 → 25.16 2 → 2 3.03 → 2.96
fresh Find Next 1 → 1 37.21 → 39.2 1 → 1 1.35 → 1.24
fresh Clear query 2 → 2 21.98 → 20.92 4 → 4 5.25 → 5.13
traversed Open with retained query 251 → 2 312.5 → 39.69 2 → 1 4.25 → 2.46
traversed Type one character 251 → 2 289.41 → 28.19 2 → 2 22.73 → 3.73
traversed Find Next 1 → 1 45.31 → 42.17 1 → 1 1.71 → 1.61
traversed Clear query 251 → 2 275.46 → 24.13 4 → 4 22.14 → 5.99

After traversal, the median paired paint changes were -272.81 ms for open and -260.86 ms for typing. The candidate was faster in 4/4 open pairs and 4/4 typing pairs. Each table entry is baseline → candidate. Paint is the first renderer-main-thread paint after the expected panel update. Forced layout counts use Chromium trace attribution. The sample covers one fixture and one browser. The paint proxy measures renderer work before display presentation.

After a notebook has been traversed, most mounted editors are offscreen. Deliver each query to visible views and refresh a returning editor from the shared query. Keep match enumeration and replacement on the document layer so dormant editors remain searchable.
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 1be5cd4.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report for ./frontend

Status Category Percentage Covered / Total
🔵 Lines 69.63% 28909 / 41518
🔵 Statements 69.58% 29476 / 42359
🔵 Functions 65.09% 6976 / 10717
🔵 Branches 65.11% 16962 / 26050
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
frontend/src/__mocks__/intersection-observer.ts 92.3% 100% 85.71% 92.3% 15
frontend/src/components/editor/actions/pair-with-agent-modal.tsx 95.16% 91.17% 90.47% 96.66% 44, 259, 266
frontend/src/components/find-replace/find-replace.tsx 0% 0% 0% 0% 35-271
frontend/src/core/codemirror/find-replace/navigate.ts 100% 97.67% 100% 100%
frontend/src/core/codemirror/find-replace/search-highlight.ts 98.18% 92.3% 100% 98.14% 123
frontend/src/utils/shared-intersection-observer.ts 100% 84.61% 100% 100%
Generated in workflow #26521 for commit 1be5cd4 by the Vitest Coverage Report Action

@kirangadhave
kirangadhave requested review from mscolnick and a balanced review from Copilot December 2, 2026 20:37
@kirangadhave
kirangadhave marked this pull request as ready for review December 2, 2026 20:37
@kirangadhave kirangadhave added the internal A refactor or improvement that is not user facing label Dec 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the notebook Find performance changes.

No open issues 🎉

What changed in this PR

Improves notebook Find performance by sharing one highlight query and updating only visible editors, while preserving search across unmounted cell documents.

Changes:

  • Synchronizes highlights when editors enter the viewport.
  • Skips unchanged selection resets and refreshes match counts after undoing Replace All.
  • Expands coverage for highlight lifecycle, navigation, and unmounted-cell replacements.
File Description
frontend/​src/​utils/​shared-intersection-observer.ts Supports a custom visibility predicate.
frontend/​src/​core/​codemirror/​find-replace/​search-highlight.ts Shares highlight queries and subscribes visible editors.
frontend/​src/​core/​codemirror/​find-replace/​navigate.ts Avoids redundant selection resets.
frontend/​src/​core/​codemirror/​find-replace/​__tests__/​unmounted-cells.test.ts Expands regex navigation, replacement, and undo coverage.
frontend/​src/​core/​codemirror/​find-replace/​__tests__/​search-highlight.test.ts Tests viewport synchronization and subscription cleanup.
frontend/​src/​core/​codemirror/​find-replace/​__tests__/​navigate.test.ts Tests skipped and required selection resets.
frontend/​src/​components/​find-replace/​find-replace.tsx Removes global highlight dispatches and refreshes counts after undo.
frontend/​src/​__mocks__/​intersection-observer.ts Allows explicit intersection ratios in tests.

Review effort: Balanced

@kirangadhave kirangadhave changed the title Limit Find highlights to visible editors perf: Limit Find highlights to visible editors Dec 2, 2026
mscolnick
mscolnick previously approved these changes Dec 2, 2026
The reset can fire after the modal unmounts and Vitest removes the
browser environment. Tie the timer to the confirmation state so
unmounting cancels it.
@kirangadhave
kirangadhave enabled auto-merge (squash) December 3, 2026 00:56
@kirangadhave kirangadhave changed the title perf: Limit Find highlights to visible editors perf: limit Find highlights to visible editors Dec 3, 2026
mscolnick
mscolnick previously approved these changes Dec 3, 2026
@mscolnick
mscolnick disabled auto-merge December 3, 2026 04:53
@mscolnick
mscolnick merged commit e2d7d65 into main Dec 3, 2026
30 checks passed
@mscolnick
mscolnick deleted the kg/visible-find-highlights branch December 3, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants